package classes;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.User;

import libs.DataBase;

public class IndexClass {
	private DataBase db;
	
	public IndexClass() {
		this.db = DataBase.getInstance();
		db.Connect();
	}
	
	public List<User> getPersons() {
		List<User> persons = new ArrayList<>();
		ResultSet resultSetFromUsers = this.db.Select(new String[]{"*"}, new String[]{"user"}, "", "");

        try {
            while(resultSetFromUsers.next()){
                persons.add(new User(
                		new Integer(resultSetFromUsers.getObject("id").toString()).intValue(),
                		resultSetFromUsers.getObject("Name").toString(),
                		resultSetFromUsers.getObject("Surname").toString(),
                		resultSetFromUsers.getObject("Middlename").toString(),
                		resultSetFromUsers.getObject("Cellphone").toString(),
                		resultSetFromUsers.getObject("Homephone").toString(),
                		resultSetFromUsers.getObject("Mail").toString(),
                		resultSetFromUsers.getObject("Address").toString()
                		));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return persons;
	}
	
	public void delPersons(String ids) {
		String where = "id IN ("+ids+")";
		this.db.Delete("user", where);
	}
     
	
}
